package com.neuedu.javase;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-22 9:01
 * 描述 : 位运算
 */
public class Operator5 {


    /**
     *          8421
     * 1        0001
     * 2        0010
     * 3        0011
     * 4        0100
     * 5        0101
     * 6        0110
     * 7        0111
     * 8        1000
     * 9        1001
     *
     *
     * @param args
     */
    public static void main(String[] args) {
        int numa = 3;   //0 0 1 1
        int num5 = 5;   //0 1 0 1

//        按位与
        //  0 0 1 1
        //  0 1 0 1
        //& 0 0 0 1
        System.out.println("numa & num5 = " + (numa & num5));



        //        按位与
        //  0 0 1 1
        //  0 1 0 1
        //| 0 1 1 1
        System.out.println("numa | num5 = " + (numa|  num5));


        //        按位与
        //  0 0 1 1
        //  0 1 0 1
        //| 0 1 1 1
        System.out.println(" ~num5 = " + (   ~num5));


        //        按位与
        //  0 0 1 1
        //  0 1 0 1
        //^ 0 1 1 0
        System.out.println("numa ^ num5 = " + (numa ^  num5));

//        0010      0100
         int numb = 2;
        System.out.println("numb>>1 = " + (numb >> 1)); //1
        System.out.println("numb<<1 = " + (numb << 1)); //4
        System.out.println("numb>>>1 = " + (numb >>> 1)); //4     符号位  正数0  负数  1
        System.out.println("-2>>>1 = " + (-2 >>> 1)); //4     符号位  正数0  负数  1


        /**
         * 三目运算符
         *
         *
         *            表达式？“真”：“假”
         *
         *
         */

        int age = 60;
        char gender = '男';

        //男性是否能退休的提示
        String str = (age>=60 && gender=='男')?"可以退休":"不能退休";
        System.out.println();
        System.out.println("str = " + str);

    }




}
